<template>
  <div class="box">
        <div class="box-row-1">
            <el-form :model="ruleform" ref="ruleForm">
                <div class="box-form">
                    <el-form-item label="部门名称" class="displayClass">
                        <el-input v-model="ruleform.dept_name" placeholder="请输入部门名称"></el-input>
                    </el-form-item>

                    <el-form-item label="启用状态" class="displayClass">
                        <el-select v-model="ruleform.State" placeholder="请选择" clearable>
                            <el-option v-for="item in options" :key="item.value"
                                :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item>
                        <el-button class="el-button--mini" type="primary" icon="el-icon-search" @click="submitForm('ruleForm')">搜索</el-button>
                        <el-button class="el-button--mini" @click="resetForm('ruleForm')" icon="el-icon-refresh">重置</el-button>
                    </el-form-item>
                </div>
            </el-form>
        </div>

        <div class="box-row-3">
            <el-table
            height="calc(100vh - 550px)"
            :data="tableData"
            v-loading="isloading"
            style=";margin-bottom: 20px;"
            default-expand-all
            row-key="dept_id"
            :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                <el-table-column
                    prop="dept_name"
                    label="部门名称" width="200">
                </el-table-column>
                <el-table-column
                    prop="order_num"
                    label="排序" width="200">
                </el-table-column>
                <el-table-column prop="status" label="是否启用" width="80" align="center">
                        <template slot-scope="scope">
                            <el-tag :type="scope.row.status == 0 ? 'primary' : 'danger'" disable-transitions>
                                <div v-if="scope.row.status == 0">正常</div>
                                <div v-else>停用</div>
                            </el-tag>
                        </template>
                </el-table-column>
                
                <el-table-column prop="create_time" label="创建时间" width="250" align="center" :show-overflow-tooltip="true"></el-table-column>
                
                <el-table-column fixed="right" label="操作" align="center" >
                    <template slot-scope="scope">
                        <el-button @click="SelectChange(scope.row)" type="text" size="small" icon="el-icon-check">选择</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return{
            options:[{
                    value: '0',
                    label: '正常'
                },{
                    value:'1',
                    label:'停用'
                }
            ],
            ruleform:{
                dept_name:'',
                State:''
            },
            tableData: [],
            isloading:false,
        }
    },
methods:{
    SelectChange(e){
        this.$emit('SelectChange',e)
    },
    submitForm(formName){
            this.$refs[formName].validate((valid)=>{
                if(valid){
                    this.dataBind();
                }else{
                    console.log('err')
                }
            })
        },
    resetForm(formName){
        this.$refs[formName].resetFields()
    },
    dataBind(){
            this.$http.request({
                type:'get',
                url:'/api/DepartmentManage',
                params:{
                DName:this.ruleform.dept_name,
                Status:this.ruleform.State
            }
        }).then(res=>{
            console.log(res.data);
            if(res.data.code==200){
                this.tableData=res.data.data;
            }
        }).catch(err=>{
            this.ShowMsg('服务器异常','error');
            console.log(err)
        }).finally(()=>{
            this.isloading=false;
        })
    },
},
created(){
    this.dataBind();
}
}
</script>

<style scoped>
</style>